
var path = require("path");
var fs  = require("fs");
var config = require("./config.json");

var deploy = require("./deploy")(config);

config.root_dir = __dirname;

exports.build = function(app_name){
    
    //copy_config(config,app_config);
   

    var app_config = require(path.join("../",app_name,"config.json"));
    var app_module = {
        pre_url:"",
        app_name:app_name,
        app_root:"..",
        config:app_config
    }
    
    //console.log(config.root_dir,app_module.app_root,app_module.app_name,"index.html")

    var tpl_dir = path.join(config.root_dir,app_module.app_root,app_module.app_name,"index.html");



    var html = deploy.compile(tpl_dir,{
        app_module:app_module
    });

    var build_dir = path.join(config.root_dir,app_module.app_root,app_module.app_name,"index.build.html");

    //var html = platform_deployer.compile();

    fs.writeFile(build_dir,html,function(err){
        if(err){
            console.dir(err);
        }        
    });

    
}





